<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/8/3
 * Time: 15:47
 */

namespace Zch\LishangLaravelShop\Wap\Member\Http\Controllers;

use Illuminate\Http\Request;
use Zch\LishangLaravelShop\Wap\Member\Facades\Member;
use Zch\LishangLaravelShop\Wap\Member\Models\User;


class AuthController extends Controller
{
    public function getWechatUserInfo(Request $request)
    {
        $userInfo = session('wechat.oauth_user.default');
        $rowInfo = User::where('openid', $userInfo->ids)->first();

        if(!$rowInfo){
            $result = User::create([
               'nickname'     => $userInfo->nickname,
               'openid'       => $userInfo->original['openid'],
               'head_img_url' => $userInfo->avatar,
               'created_at'   => date('Y-m-d H:i:s')
            ]);
        }else{
            $result = User::where(['openid' => $userInfo->original['openid']])->update([
                'nickname'     => $userInfo->nickname,
                'head_img_url' => $userInfo->avatar,
            ]);
        }

        //改变用户登录状态
        //Auth::login($rowInfo);
        //var_dump(Auth::check());
        //Member::guard()->login($rowInfo);
        Member::login($rowInfo);
        var_dump(Member::check());
        return '通过';
        //return redirect()->route('wap.member.index');
     }
}
